package Salesman;

import Salesman.event.StepEvent;
import Salesman.event.StepListener;
import java.util.LinkedList;
import java.util.List;

public abstract class TSPEngine {

    private List<StepListener> listeners = new LinkedList<StepListener>();
    private boolean stepped = false;
    private int counter = 0;
    private Distances distances;

    /**
     * Listener hinzufügen
     * @param al
     */
    public void addStepListener(StepListener l) {
        listeners.add(l);
    }

    /**
     * Listener entfernen
     * @param al
     */
    public void removeStepListener(StepListener l) {
        listeners.remove(l);
    }

    /**
     * alle Listener benachrichtigen
     */
    protected void fireListener(AbstractStep step) {
        StepEvent e = new StepEvent(this, step);
        for (StepListener l : listeners) {
            l.nextStep(e);
        }
    }

    /**
     * Counter zurücksetzen
     */
    public void resetCounter() {
        counter = 0;
    }

    /**
     * counter erhöhen
     */
    public void incCounter() {
        counter++;
    }

    /**
     * Counter zurückgeben
     * @return
     */
    public int getCounter() {
        return counter;
    }

    public abstract void start(City city);

    public abstract boolean next();

    /**
     * Schrittbetrieb?
     * @return
     */
    public boolean isStepped() {
        return stepped;
    }

    /**
     * Schrittbetrieb an/aus
     * @param stepped
     */
    public void setStepped(boolean stepped) {
        this.stepped = stepped;
    }

    @Override
    public String toString() {
        return getClass().getSimpleName();
    }
}
